Expand description
This crate provides a generate that constructs random name strings suitable for use in container instances, project names, application instances, etc.
The name Generator
implements the Iterator
trait so it can be used with
adapters, consumers, and in loops.
Usage
This crate is on crates.io and can be
used by adding names
to your dependencies in your project’s Cargo.toml
file:
[dependencies]
names = { version = "0.14.0", default-features = false }
Examples
Example: painless defaults
The easiest way to get started is to use the default Generator
to return
a name:
use names::Generator;
let mut generator = Generator::default();
println!("Your project is: {}", generator.next().unwrap());
// #=> "Your project is: rusty-nail"
If more randomness is required, you can generate a name with a trailing 4-digit number:
use names::{Generator, Name};
let mut generator = Generator::with_naming(Name::Numbered);
println!("Your project is: {}", generator.next().unwrap());
// #=> "Your project is: pushy-pencil-5602"
Example: with custom dictionaries
If you would rather supply your own custom adjective and noun word lists, you can provide your own by supplying 2 string slices. For example, this returns only one result:
use names::{Generator, Name};
let adjectives = &["imaginary"];
let nouns = &["roll"];
let mut generator = Generator::new(adjectives, nouns, Name::default());
assert_eq!("imaginary-roll", generator.next().unwrap());
Structs
A random name generator which combines an adjective, a noun, and an optional number
Enums
A naming strategy for the Generator
Constants
List of English adjective words
List of English noun words